$(function(){
   
    var mycomment = new Mycomment();
    mycomment.init().init();
    
});

function Mycomment(){
    this.init = function(){
        return MYCOMMENT;
    };
    
    var MYCOMMENT = {
        init : function(){
            this.listeners.bindEvents();
            
        },
        listeners : {
            bindEvents : function(){
                $.util.foreachFunction(this, [ "bindEvents" ]);
            },
            bindMofiy : function(){
                $("#p_comment_fun a.mofiycomment").click(function(){
                    //将comment id 添加至
                    $("#review-popup-content").attr('c_id', $(this).attr('c_id'));
                    $.post(SYSTEM_DATA.contextPath + '/User/ajaxCommentText.shtml', {
                        'id' : $(this).attr('c_id')
                    }, function(jsonResult){
                        if(jsonResult){
                            $("#review-popup-content").val(jsonResult.data.comment);
                            //显示写评论Dialog
                            $dialog = $("#review-popup");
                            $dialog.removeClass('hidden');
                            MYCOMMENT.funs.initDialog($dialog, '写评论', 500, 400);
                        }
                    }, 'json');
                });
            },
            bindMofiyComment : function(){
                //comment submit
                $("#normal-review-button").click(function(){
                    var $comment = $("#review-popup-content");
                    $.post(SYSTEM_DATA.contextPath + '/User/ajaxComment.shtml', {
                        'id' : $comment.attr('c_id'),
                        'comment' : $comment.val()
                    }, function(jsonResult){
                        if(jsonResult.data){
                            window.location.reload();
                        }
                    }, 'json');
                });
            },
            bindDelete : function(){
                $("#p_comment_fun a.deletecomment").click(function(){
                    if(confirm('是否确定删除？')){
                        $.util.initHiddenFormSubmit($('#frm_hidden_mycomment'),SYSTEM_DATA.contextPath + '/User/deleteComment.shtml',  [{
                            'name' : 'id', 
                            'value' : $(this).attr('c_id')
                        }]);
                    }
                });
            }
        },
        funs : {
            initDialog : function($dialog, title){
                $dialog.dialog({
                    'title' : title,
                    'resizable': false,
                    'width' : arguments[2] ? arguments[2] : 700,
                    'height': arguments[3] ? arguments[3] : 440,
                    'modal': true
                });
            }
        }
    };
}




